#define _CRT_SECURE_NO_WARNINGS 1

#include"BinaryTree.h"

BTNode* CreateNode(BTDataType x)
{
	BTNode* node = (BTNode*)malloc(sizeof(BTNode));
	if (node == NULL)
	{
		perror("malloc fail");
		return NULL;
	}
	node->data = x;
	node->left = NULL;
	node->right = NULL;
	return node;
}
BTNode* CreateBinaryTree()
{
	BTNode* node1 = CreateNode(1);
	BTNode* node2 = CreateNode(2);
	BTNode* node3 = CreateNode(3);
	BTNode* node4 = CreateNode(4);
	BTNode* node5 = CreateNode(5);
	BTNode* node6 = CreateNode(6);
	node1->left = node2;
	node1->right = node4;
	node2->left = node3;
	node4->left = node5;
	node4->right = node6;
	return node1;
}
void Prevorder(BTNode* root)// 1 2 3 N N N 4 5 N N 6 N N
{
	if (root == NULL)
	{
		printf("N ");
		return;
	}
	printf("%d ", root->data);
	Prevorder(root->left);
	Prevorder(root->right);
}
void Inorder(BTNode* root) // N 3 N 2 N 1 N 5 N 4 N 6 N
{
	if (root == NULL)
	{
		printf("N ");
		return;
	}
	Inorder(root->left);
	printf("%d ", root->data);
	Inorder(root->right);
}
void Postorder(BTNode* root) //N N 3 N 2 N N 5 N N 6 4 1
{
	if (root == NULL)
	{
		printf("N ");
		return;
	}
	Postorder(root->left);
	Postorder(root->right);
	printf("%d ", root->data);
}


int BinaryTreeSize(BTNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	return BinaryTreesize(root->left) + BinaryTreesize(root->right) + 1;
}

int BinaryTreeLeafSize(BTNode* root)
{
	if (root == NULL)
		return 0;
	if (root->left == NULL && root->right == NULL)
		return 1;
	return BinaryTreeLeafSize(root->left) + BinaryTreeLeafSize(root->right);

}

int BinaryTreeFloorSize(BTNode* root)
{
	if (root == NULL)
		return 0;
	int left = BinaryTreeFloorSize(root->left);
	int right = BinaryTreeFloorSize(root->right);
	return left > right ? left + 1: right + 1;
}

int BinaryTreeLevelKSize(BTNode* root, int k)
{
	assert(k > 0);

}